<template>
	<el-form-item :label="label==undefined?'消息提醒':label" v-show="this.isShowMsg">
	<el-checkbox @change="getMsgTypeVal" v-model="this.form.webSms" label="站内消息" v-if="this.msgConf.webSms!='0'" :checked="this.msgConf.webSms=='2'" :disabled="this.msgConf.webSms=='2'"></el-checkbox>
		<el-checkbox @change="getMsgTypeVal" v-model="this.form.emailSms" label="外部邮件" v-if="this.msgConf.emailSms!='0'" :checked="this.msgConf.emailSms=='2'" :disabled="this.msgConf.emailSms=='2'"></el-checkbox>
	<el-checkbox @change="getMsgTypeVal" v-model="this.form.mobileSms" label="手机短信" v-if="this.msgConf.mobileSms!='0'" :checked="this.msgConf.mobileSms=='2'" :disabled="this.msgConf.mobileSms=='2'"></el-checkbox>
	<el-checkbox @change="getMsgTypeVal" v-model="this.form.wxSms" label="微信消息" v-if="this.msgConf.wxSms!='0'" :checked="this.msgConf.wxSms=='2'" :disabled="this.msgConf.wxSms=='2'"></el-checkbox>
	<el-checkbox @change="getMsgTypeVal" v-model="this.form.ddSms" label="钉钉消息" v-if="this.msgConf.ddSms!='0'" :checked="this.msgConf.ddSms=='2'" :disabled="this.msgConf.ddSms=='2'"></el-checkbox>
	<el-checkbox @change="getMsgTypeVal" v-model="this.form.appSms" label="APP消息" v-if="this.msgConf.appSms!='0'" :checked="this.msgConf.appSms=='2'" :disabled="this.msgConf.appSms=='2'"></el-checkbox>
	</el-form-item>
</template>
<script>
export default {
	props:{
		label:{type:String},
		msgType:{type: String},
		code:{
			type: Object //Object是对象，String是字符串，Array是数组
		},
	},
	data() {
		return{
			msgConf:{
				webSms:'',
				emailSms:'',
				mobileSms:'',
				wxSms:'',
				ddSms:'',
				appSms:'',
			},
			isShowMsg:true,
			form:{
				webSms:false,
				emailSms:false,
				mobileSms:false,
				wxSms:false,
				ddSms:false,
				appSms:false
			},
			resMsgType:''
		}
	},
	watch: {
		msgType(){
			this.initSysMsgConfig();
		}
	},
	mounted() {
		this.resMsgType = this.msgType;
		this.initSysMsgConfig();
	},
	methods:{
		async initSysMsgConfig()
		{
			var params = {
				code: this.code
			}
			var res = await this.$API.system.sysMsgConfig.getSysMsgConfigByCode.get(params);
			if (res.code == 200) {
				if(res.data!=null)
				{
					this.msgConf.appSms = res.data.appSms;
					if(this.msgConf.appSms=="2")
					{
						this.form.appSms = true;
					}
					this.msgConf.webSms = res.data.webSms;
					if(this.msgConf.webSms=="2")
					{
						this.form.webSms = true;
					}
					this.msgConf.wxSms = res.data.wxSms;
					if(this.msgConf.wxSms=="2")
					{
						this.form.wxSms = true;
					}
					this.msgConf.ddSms = res.data.ddSms;
					if(this.msgConf.ddSms=="2")
					{
						this.form.ddSms = true;
					}
					this.msgConf.mobileSms = res.data.mobileSms;
					if(this.msgConf.mobileSms=="2")
					{
						this.form.mobileSms = true;
					}
					this.msgConf.emailSms = res.data.emailSms;
					if(this.msgConf.emailSms=="2")
					{
						this.form.emailSms = true;
					}
					if(this.msgConf.appSms!='0'||this.msgConf.emailSms!='0'||this.msgConf.webSms!='0'||this.msgConf.wxSms!='0'||this.msgConf.ddSms!='0'||this.msgConf.mobileSms!='0')
					{
						this.isShowMsg = true;
					}else
					{
						this.isShowMsg = false
					}
					this.getMsgTypeVal();
				}else
				{
					this.$alert("信息提醒方式获取失败", "提示", {type: 'error'})
				}

			}
		},
		getMsgTypeVal()
		{
			var resArr= [];
			if(this.form.webSms)
			{
				resArr.push("webSms")
			}
			if(this.form.emailSms)
			{
				resArr.push("emailSms")
			}
			if(this.form.mobileSms)
			{
				resArr.push("mobileSms")
			}
			if(this.form.wxSms)
			{
				resArr.push("wxSms")
			}
			if(this.form.ddSms)
			{
				resArr.push("ddSms")
			}
			if(this.form.appSms)
			{
				resArr.push("appSms");
			}
			this.$emit('update:msgType', resArr.join(","));
		},
	}
}
</script>
